var formatJson = function (json, options) {
 var reg = null,
   formatted = '',
   pad = 0,
   PADDING = '    ';
 options = options || {};
 options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
 options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
 if (typeof json !== 'string') {
  json = JSON.stringify(json);
 } else {
  json = JSON.parse(json);
  json = JSON.stringify(json);
 }
 reg = /([\{\}])/g;
 json = json.replace(reg, '\r\n$1\r\n');
 reg = /([\[\]])/g;
 json = json.replace(reg, '\r\n$1\r\n');
 reg = /(\,)/g;
 json = json.replace(reg, '$1\r\n');
 reg = /(\r\n\r\n)/g;
 json = json.replace(reg, '\r\n');
 reg = /\r\n\,/g;
 json = json.replace(reg, ',');
 if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
  reg = /\:\r\n\{/g;
  json = json.replace(reg, ':{');
  reg = /\:\r\n\[/g;
  json = json.replace(reg, ':[');
 }
 if (options.spaceAfterColon) {
  reg = /\:/g;
  json = json.replace(reg, ':');
 }
 (json.split('\r\n')).forEach(function (node, index) {
    var i = 0,
      indent = 0,
      padding = '';

    if (node.match(/\{$/) || node.match(/\[$/)) {
     indent = 1;
    } else if (node.match(/\}/) || node.match(/\]/)) {
     if (pad !== 0) {
      pad -= 1;
     }
    } else {
     indent = 0;
    }

    for (i = 0; i < pad; i++) {
     padding += PADDING;
    }

    formatted += padding + node + '\r\n';
    pad += indent;
   }
 );
 return formatted;
}

 //写cookies
function setCookie(name,value,del)
{
    if (!del) {
        var Days = 1;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*1*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/";
    } else {
        var Days = 1;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*1*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=-1;path=/";
    }

}

//读取cookies
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
function onUrl(url){
    //判断
    if(url){
       //  'width: expression(this.parentNode.offsetWidth);' +
       // 'height: expression(this.parentNode.offsetHeight);' +
        window.location.href=url;
        setCookie("default_url",url);

    }
}


// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//setcooker by
function setCookiebym(cname,cvalue,exdays)
{
  var d = new Date();
  d.setTime(d.getTime()+(exdays*60*1000));
  var expires = "expires="+d.toGMTString();
  document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookiebym(cname)
{
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++)
  {
    var c = ca[i].trim();
    if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
  return "";
}



